package com.lmk.ms.common.db.influx.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * InfluxDB 配置
 *
 * @author laomake@hotmail.com
 * @version 1.0
 * @date 2022/9/20
 */
@Component
@ConfigurationProperties(prefix = "ms.config.db.influx")
public class InfluxProperties {

    /**
     * 是否启用
     */
    private Boolean enabled;

    /**
     * InfluxDB版本：1或2
     */
    private Integer version = 2;

    /**
     * InfluxDB连接地址
     */
    private String url;

    /**
     * V1参数：数据库名称
     */
    private String database;

    /**
     * V1参数：用户名
     */
    private String username;

    /**
     * V1参数：密码
     */
    private String password;

    /**
     * V1参数：保存策略名称
     */
    private String retentionPolicy;

    /**
     * V2参数：访问令牌
     */
    private String token;

    /**
     * V2参数：组织
     */
    private String org;

    /**
     * V2参数：桶名称
     */
    private String bucket;

    public InfluxProperties() {
    }

    public Boolean getEnabled() {
        return enabled;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public String getDatabase() {
        return database;
    }

    public void setDatabase(String database) {
        this.database = database;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getRetentionPolicy() {
        return retentionPolicy;
    }

    public void setRetentionPolicy(String retentionPolicy) {
        this.retentionPolicy = retentionPolicy;
    }

    public String getToken() {
        return token;
    }

    public void setToken(String token) {
        this.token = token;
    }

    public String getOrg() {
        return org;
    }

    public void setOrg(String org) {
        this.org = org;
    }

    public String getBucket() {
        return this.version == 2 ? this.bucket : getV1Bucket();
    }

    public void setBucket(String bucket) {
        this.bucket = bucket;
    }

    public String getV1Bucket() {
        return this.getDatabase() + "/" + this.retentionPolicy;
    }

    public String getV2Bucket() {
        return this.bucket;
    }
}
